home *** CD-ROM | disk | FTP | other *** search
/ The Essential Home & Business Collection / The Essential Home & Business Collection.iso / 27 / 3 / 5 / HP22D5.ZIP / EXTERN / RUNABS.C < prev    next >
Text File  |  1991-04-16  |  2KB  |  75 lines

  1. #include <dos.h>
  2.  
  3. #include "extern.h"        /* Extensions need these! */
  4.  
  5. extern pascal far clearbuf();
  6.  
  7. pascal near value(char c)
  8.  
  9. {
  10.     if (c >= '0' && c <= '9') return(c - '0');
  11.     if (c >= 'a' && c <= 'f') return(c - 'a' + 10);
  12.     if (c >= 'A' && c <= 'F') return(c - 'A' + 10);
  13. }
  14.  
  15. /*
  16. ** RUNABS
  17. **
  18. ** This handler calls an absolute ROM address. The passed address takes the
  19. ** form SEGMENT:OFFSET, for example: F000:200. The address is converted to
  20. ** an internal representation and called just like any other routine. It is
  21. ** the responsibility of the ROM routine to preserve all of the registers
  22. ** that it modifies and to return via a normal retf instruction.
  23. **
  24. ** The routine performs the following steps:
  25. **
  26. **    1. convert the address to internal format
  27. **    2. Release HyperPAD's interrupts, providing a well behaved environment
  28. **    3. Call the absolute address routine
  29. **    4. Clear the keyboard buffer (some ROM routines incorrectly do this)
  30. **    5. Restore HyperPAD, including the screen mode
  31. **    6. Return to HyperPAD
  32. **
  33. ** Example:
  34. **
  35. **    runabs f000:200;
  36. */
  37. runabs(int NumArgs,HANDLE hAddress)
  38.  
  39. {
  40.     PTR p,s;
  41.     register int i,n;
  42.     WORD w;
  43.     RTN rtn;
  44.  
  45.     if (NumArgs != 1) return(STOP);
  46.  
  47.     for (s=p=deref(hAddress);*s && *s != ':';s++);
  48.  
  49.     for (i=s-p-1,w=0;i>= 0;i--) w |= value(*p++) << (i*4);
  50.     FP_SEG(rtn) = w;
  51.  
  52.     for (p=++s;*s;s++);
  53.  
  54.     for (i=(s-p)-1,w=0;i>= 0;i--) w |= value(*p++) << (i*4);
  55.     FP_OFF(rtn) = w;
  56.  
  57.     ReleaseHPAD();
  58.     (*rtn)();
  59.     clearbuf();
  60.     RestoreHPAD();
  61.  
  62.     return(STOP);
  63. }
  64.  
  65. POOL pascal Pool[] = {
  66.     {    "runabs",        /* name of the handler */
  67.         runabs,            /* pointer to the handler */
  68.         0,            /* reserved */
  69.         HANDLER},        /* this is a handler, not a function */
  70.  
  71.     {    NULL,            /* NULLs signify the end of the table */
  72.         NULL,
  73.         0,
  74.         0}    };
  75.